package com.example.edu.pay;

import com.example.edu.pay.enums.PayType;
import com.example.edu.pay.handler.PayHandler;
import com.example.edu.pay.handler.impl.AliPayHandler;
import com.example.edu.pay.handler.impl.WxPayHandler;
import com.example.edu.pay.model.PayOrder;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yanzhao
 * @date 2022/2/18 15:13
 * @since 1.0.0
 */
public class PayContext {

    private Map<String, PayHandler> map = new HashMap<>();

    public PayContext() {
        map.put(PayType.WX_PAY.name(), new WxPayHandler());
        map.put(PayType.ALI_PAY.name(), new AliPayHandler());
    }

    public void doPay(PayOrder payOrder) {
        map.get(payOrder.getPayMethod()).handle(payOrder);
    }
}
